package com.cyurs.netty.nettySimple.EncoderAndDecoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;

import java.util.List;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/26
 */
public class LongToMessageDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("LongToMessageDecoder decoder 被调用了");
        //因为Long类型为8个字节
        if (in.readableBytes() >= 8) {
            out.add(in.readLong());
        }
    }
}
